package project.layer.agents;

import framework.events.EventBroker;
import project.events.truckEvents.TruckFollowedRoadEvent;
import project.layer.ant.IntentionAnt;
import project.layer.physical.Truck;
import project.layer.physical.commands.EnterCrossroadCommand;
import project.layer.physical.commands.MoveForwardCommand;

public abstract class TruckAgentState {
	
	private TruckAgent truckAgent;
	
	public TruckAgentState(TruckAgent truckAgent){
		this.truckAgent = truckAgent;
	}
	public abstract void processTruckTick();
	
	public boolean isPickingUpPackage(){
		return false;
	}
	
	public boolean isDeliveringPackage(){
		return false;
	}
	
	protected void driveTillNextCrossroad(){
		Truck truck = getTruckAgent().getTruck();
		if(!truck.isOnConnector()){
			if(truck.getConnectionPosition().getConnection().isAtEnd(truck)){
				truck.addCommand(new EnterCrossroadCommand(truck),getTruckAgent());
				EventBroker.getEventBroker().notifyAll(new TruckFollowedRoadEvent(truck, truck.getConnectionPosition().getConnection()));
			}
			else{
				truck.addCommand(new MoveForwardCommand(truck), getTruckAgent());
			}
		}
	}
	public TruckAgent getTruckAgent() {
		return truckAgent;
	}
	
	public void resetExplorationMaxHopCount(){
		
	}
	
	protected void renewIntention(){
		IntentionAnt iAnt = new IntentionAnt(getTruckAgent(), getTruckAgent().getTruck().getConnectorPosition().getConnector(), getTruckAgent().getIntention().getClone());
		
	}
	
	
}
